/**
 * @description spider 控制
 * @author 盘古他爹
 */


import ResponseModel from "../config/response.config"
import * as puppeteer from "puppeteer"
class SpiderController {

  async test(ctx: any) {
    console.log("可以");

    // const puppeteer = require('puppeteer');
    const browser = await puppeteer.launch({ headless: false });

    const page = await browser.newPage();
    await page.goto("https://cn.vuejs.org/v2/guide/");
    const loc = page.browser()
    console.log("loc", loc);
    const url = await browser.wsEndpoint();
    // console.log("browser", targets.browser());
    // console.log("page", await puppeteer.executablePath());
    const content = page.target()
    const content2 = await page.mainFrame().content()
    console.log("url", content2);

    // return page
    // await page.screenshot({ path: 'example.png' });


    //   await browser.close();

    ctx.body = ResponseModel.success({ content }, "成功")
    // ctx.body = ResponseModel.success({ loc: browser.browserContexts() }, "成功")
  }


}

export default new SpiderController()